package com.hj.system.common.controller;

import com.hj.system.base.utils.PageUtils;
import com.hj.system.base.utils.ResponseUtil;
import com.hj.system.common.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequestMapping("/common/log")
@Controller
public class LogController {
    @Autowired
    LogService logService;
    String prefix = "common/log";

    @GetMapping()
    public String log() {
        return prefix + "/log";
    }

    @ResponseBody
    @GetMapping("/list")
    public Map<String, Object> list(@RequestParam Map<String, Object> params) {
        PageUtils pageUtils = logService.list(params);
        return ResponseUtil.okContent(pageUtils);
    }

    @ResponseBody
    @PostMapping("/remove")
    ResponseUtil remove(String id) {
        if (logService.remove(id) > 0) {
            return ResponseUtil.ok();
        }
        return ResponseUtil.error();
    }

    @ResponseBody
    @PostMapping("/batchRemove")
    ResponseUtil batchRemove(@RequestParam("ids[]") String[] ids) {
        int r = logService.batchRemove(ids);
        if (r > 0) {
            return ResponseUtil.ok();
        }
        return ResponseUtil.error();
    }
}
